<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* '23'
            思路：这种组合类问题一定是用回溯法
            ①：确定终止条件
            当path.length==digits.length return
            ②：确定循环遍历范围
            每次遍历的是对应的字母集合 2:'abc'  start从0开始 每次+1
            */
            var letterCombinations = function (digits) {
                if (!digits.length) return []
                const map = { 2: "abc", 3: "def", 4: "ghi", 5: "jkl", 6: "mno", 7: "pqrs", 8: "tuv", 9: "wxyz" }
                let res = []
                function backTracking(path, start) {
                    if (path.length == digits.length) {
                        return res.push([...path].join(""))
                    }
                    let str = map[digits[start]]
                    for (let i = 0; i < str.length; i++) {
                        path.push(str[i])
                        backTracking(path, start + 1)
                        path.pop()
                    }
                }
                backTracking([], 0)
                return res
            }
        </script>
    </body>
</html>
